package com.epoint.mobileoa.personalized.epointcompany.ui.kaoqing;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.dom4j.Element;

import android.os.Message;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.ConfigKey;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.bizlogic.Task;
import com.epoint.mobileoa.datanalysis.XMLHelp;
import com.epoint.mobileoa.db.DBHelp;
import com.epoint.mobileoa.personalized.epointcompany.model.QiandaoInfoModel;
import com.epoint.mobileoa.tools.WebServiceUtilDAL;

/**
 * @author liyc
 * @time 2012-8-7 上午11:21:19
 * @annotation 
 */
public class QDTask extends Task {

	/**
	 * @param con
	 * @param param
	 */
	public QDTask(SuperView con, Map<String, Object> param) {
		super(con, param);
	}

	@Override
	public void exectue(Message mess) throws Exception {
		String address = (String) getParam().get("address");

		String url = getCon().getString(R.string.epointcompany_kaoqin_url);
		String namespace = getCon().getString(
				R.string.epointcompany_rizhi_namespace);
		String method = "MobileWorkAttendanceInsert";
		WebServiceUtilDAL webservice = new WebServiceUtilDAL(url, method,
				namespace);
		webservice.addProperty("UserName",getFP().getDisplayname());
		webservice.addProperty("UserGuid", getFP().getUserguid());
		webservice.addProperty(
				"OUName",
				DBHelp.getUserOuname(getCon(),
						DBHelp.getConfigValue(getCon(), ConfigKey.userguid)));
		webservice.addProperty(
				"OUGuid",
				DBHelp.getUserOuguid(getCon(),
						DBHelp.getConfigValue(getCon(), ConfigKey.userguid)));
		webservice.addProperty("AttendLocation",address);
		String bs = webservice.start();

		setMessageToRefreshUI(mess, getCon(), bs);
	}

	public static List<QiandaoInfoModel> XmlAnalysis(String xml){
		List focs = XMLHelp.getRoot(xml).elements();
		List<QiandaoInfoModel> plist = new ArrayList<QiandaoInfoModel>();
		for (int i = 0; i < focs.size(); i++) {
			QiandaoInfoModel mt = new QiandaoInfoModel();
			Element foc = (Element) focs.get(i);
			if (foc.element("AttendTime") != null)
				mt.AttendTime = foc.elementText("AttendTime");
			if (foc.element("AttendLocation") != null)
				mt.AttendLocation = foc.elementText("AttendLocation");
			plist.add(mt);
		}
		return plist;
	}
}
